const Koa = require('koa');
const querystring = require('querystring');
const app = new Koa();
const  { cut, load, textRankExtract, extract, tag } = require('nodejieba');
load({
	userDict: __dirname + "/dict/good.utf8",
})
app.use(async ctx => {
    if (ctx.request.method === 'GET' || ctx.request.method === 'get') {
        // 解析URL中的查询字符串
        const query = ctx.request.url.split('?')[1];
        if (query) {
          const params = querystring.parse(query);
          console.log(params);
          const {title} = params
          const upData = {
            	cuts: cut(title),
            	re: textRankExtract(title, 5),
            	et: extract(title, 5),
            	tag: tag(title)
            }
            ctx.body = upData
        } else {
            ctx.body = 'No title'
        }
      } else if (req.method === 'POST') {
        ctx.body = 'No method'
      }
     
});

app.listen(7952);